package org.jeecg.modules.controller;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yaorange.jxc.goods.entity.Goods;
import com.yaorange.jxc.supplier.entity.Supplier;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.api.vo.PageVo;
import org.jeecg.modules.pojo.Purchase;
import org.jeecg.modules.pojo.PurchaseGoods;
import org.jeecg.modules.service.impl.PurchaseServiceImpl;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @company: yaorange
 * @author: Andy.Li
 * @Date: 2022.04.26 15:58:01
 */
@RestController
@RequestMapping("/tbPurchaseList")
public class PurchaseController {
    @Resource
    private PurchaseServiceImpl purchaseServiceImpl;

    //获取所有表单信息
    @GetMapping("/purchaseList")
    public ResponseEntity<?>getList(@RequestParam(value = "current",defaultValue = "1") Integer current,
                                    @RequestParam(value = "pageSize",defaultValue = "3") Integer pageSize,
                                    @RequestParam("purchaseNumber") String purchaseNumber,
                                    @RequestParam("supplierId") Integer supplierId,
                                    @RequestParam("state") Integer state,
                                    @RequestParam("purchaseDate") String purchaseDate




    ){
        Page<Purchase> page = new Page<>(current, pageSize);
        PageVo<Purchase> pageVo=purchaseServiceImpl.getPage(page,purchaseNumber,supplierId,state,purchaseDate);
        return ResponseEntity.ok(pageVo);
    }

    //获取所有进货商

    @GetMapping("/supplierlist")
    public ResponseEntity<?>getSupplierList(){
        List<Supplier> list= purchaseServiceImpl.getSupplierList();
        return ResponseEntity.ok(list);
    }

    //  新增Purchase
    @PostMapping("/addPur")
    public ResponseEntity<?>addPur(@RequestBody Purchase purchase){
        int s=purchaseServiceImpl.addPurAndPurGoods(purchase);
        return ResponseEntity.ok(s);
    }
    //  新增PurchaseGoods
    @PostMapping("/addPurGoods")
    public ResponseEntity<?>addPurGoods(@RequestBody Goods goods){
        int s=purchaseServiceImpl.addPurGoods(goods);
        return ResponseEntity.ok(s);
    }








}
